package com.netcracker.studportal.server.main_test;

import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import com.netcracker.studportal.server.model.Exam;
import com.netcracker.studportal.server.model.ExamWithResult;
import com.netcracker.studportal.server.model.Student;
import com.netcracker.studportal.server.util.FactoryDAO;

public class MainForExamResult {
	public static void main(String args[]){
		
		try {
			ExamWithResult exam=new ExamWithResult();
			exam.setExam_id(new Long(8));
			exam.setStudent_id(new Long(12));
			exam.setNote("vvv");
			exam.setMark(5);
			Exam e=new Exam();
			e.setId(new Long(15));
			//exam.setExam(ex);
			//FactoryDAO.getExamWithResultDAO().Add(exam);
			//exam=FactoryDAO.getExamWithResultDAO().getById(new Long(8), new Long(12));
		//	FactoryDAO.getExamWithResultDAO().Update(exam);
		//	FactoryDAO.getExamWithResultDAO().Delete(exam);
			
		/*	
			List <ExamWithResult> ex_res=(List<ExamWithResult>) FactoryDAO.getExamWithResultDAO().getAll();
			System.out.println(exam);
			for(int i=0;i<ex_res.size();i++){
				System.out.print(" student_id "+
						ex_res.get(i).getStudent_id()+" exam_id "+ex_res.get(i).getExam_id()
						+" note "+ex_res.get(i).getNote()+" mark "+ex_res.get(i).getMark());
				System.out.println();
			}*/
			List <Student> st=(List<Student>) FactoryDAO.getStudentDAO().getGetStudentsByExam(new Long(9));
			JSONArray list = new JSONArray();
			for(Student s:st){
				JSONObject obj=new JSONObject();				
				if(s.getId()!=null)obj.put("student_id", s.getId().toString());
				obj.put("stud_first_name", s.getFirst_name());
				obj.put("stud_last_name", s.getLast_name());				
				if(s.getCourse()!=null) obj.put("course", s.getCourse());
				if(s.getGroup_num()!=null)obj.put("group_num", s.getGroup_num().toString());				
				obj.put("stud_note", s.getNote());
								
				List <ExamWithResult> ex_res=s.getExamWithResult();
				if(ex_res!=null && ex_res.size()>0)
				for(ExamWithResult ex:ex_res){
					if(ex.getExam_id()==9) {
						if(ex.getMark()!=null) obj.put("mark",ex.getMark().toString());
						obj.put("ex_res_note", ex.getNote());
						obj.put("exam_id", ex.getExam_id());
						break;
					}
				}
				list.add(obj);
				
			}
			Iterator it=list.iterator();
			while(it.hasNext())
			System.out.println(it.next());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
